    //
//  KDMSettingCell.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/11/3.
//  Copyright © 2015年 魏强. All rights reserved.
//

#import "KDMSettingCell.h"
#import "KDMSettingCellModel.h"
@interface KDMSettingCell ()
/**
 *  cell最底部的View
 */
@property (weak, nonatomic) IBOutlet UIView *underView;
/**
 *  装关键词和次关键词的View
 */
@property (weak, nonatomic) IBOutlet UIView *wordView;

/**
 *  名字Label
 */
@property (weak, nonatomic) IBOutlet UILabel *nameLb;
/**
 *  是否单位共享Lb
 */
@property (weak, nonatomic) IBOutlet UILabel *shareLb;
/**
 *  时间Lb
 */
@property (weak, nonatomic) IBOutlet UILabel *timeLb;
/**
 *  主关键字或网址Lb
 */
@property (weak, nonatomic) IBOutlet UILabel *mainWordLb;
/**
 *  主关键字或网址btn
 */
@property (weak, nonatomic) IBOutlet UIButton *mainWordBtn;
/**
 *  次关键词LB
 */
@property (weak, nonatomic) IBOutlet UILabel *secondWord;
/**
 *  不匹配关键词LB
 */
@property (weak, nonatomic) IBOutlet UILabel *thirdWord;

/**
 *  时间label到单位共享的距离
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeToSHare_Constraint;
/**
 *  次关键词Btn
 */
@property (weak, nonatomic) IBOutlet UIButton *secondWordBtn;
/**
 *  不匹配词组的Btn
 */
@property (weak, nonatomic) IBOutlet UIButton *thirdWordBtn;

/**
 *  编辑按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *editeBtn;
/**
 *  单位共享LB的宽度约束
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareLb_Constraint_Width;
/**
 *  次关键词Lb的高度约束
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondWordBtn_Constraint_height;
/**
 *  单位lb到名字lb的中间的高度间隔
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareToName_Constraint;
/**
 *  装所有关键字的总View和上面时间View的高度间隔
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *wordViewToTimeLb_Height;
/**
 *  不匹配关键词的高度约束
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *thirdWord_Constraint_height;


@end
@implementation KDMSettingCell

- (void)awakeFromNib {
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellId =@"KDMSettingCell";
    
    UINib *xib = [UINib nibWithNibName:@"KDMSettingCell" bundle:nil];
    [tableView registerNib:xib forCellReuseIdentifier:cellId];
    KDMSettingCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.underView.layer.borderWidth = 0.2f;
    cell.underView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //    cell.numLb.layer.cornerRadius = 4.0;
    return cell;
}

- (void)setModel:(KDMSettingCellModel *)model{
    _model = model;
//    self.mainWordLb.hidden = NO;
    self.secondWord.hidden = NO;
    self.wordView.hidden = NO;
    self.secondWordBtn.hidden = NO;
    self.shareLb.hidden = NO;
    self.mainWordBtn.enabled = YES;
    self.secondWordBtn.enabled = YES;
    self.mainWordLb.text = @"关键词组";
    self.secondWord.text = @"微博词组";
    self.thirdWord.hidden = YES;
    self.thirdWordBtn.hidden = YES;
    [self.editeBtn setTitle:@"编辑" forState:UIControlStateNormal];
    self.shareLb_Constraint_Width.constant = 60;
    self.timeToSHare_Constraint.constant = 10;
    self.shareToName_Constraint.constant = 2;
    [super layoutSubviews];
    if (self.model) {
        self.nameLb.text = _model.m_Name;
        self.shareLb.text = (_model.m_Share) ? @"单位共享" :@"非单位共享";
        self.shareLb.textColor = (_model.m_Share) ? [UIColor orangeColor] : [UIColor blueColor];
        NSDate *d = [[NSDate alloc] initWithTimeIntervalSince1970:_model.m_AddTime/1000.0];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
        NSString *strDate = [dateFormatter stringFromDate:d];
        self.timeLb.text = strDate;
        if ([_model.mainType isEqualToString:@"1"]) {//说明是网站板块的
            
            self.shareLb_Constraint_Width.constant = 0;
            self.timeToSHare_Constraint.constant = 0;
            self.shareLb.hidden = YES;
            self.mainWordLb.text = @"网站地址:";
            self.mainWordBtn.enabled = YES;
            [self.mainWordBtn setTitle:_model.keyword forState:UIControlStateNormal];
            self.secondWord.text = @"";
            self.secondWord.hidden = YES;
            self.secondWordBtn.hidden = YES;
            [self.editeBtn setTitle:@"编辑网站板块" forState:UIControlStateNormal];
        }else if ([_model.mainType isEqualToString:@"2"]){//如果是作者板块的
            self.mainWordLb.text = @"";
            self.secondWord.text = @"";
            self.wordView.hidden = YES;
            self.shareToName_Constraint.constant = 20;
        }else if ([_model.mainType isEqualToString:@"3"]){//如果是微博板块
            self.mainWordLb.text = @"监测关键词:";
            self.secondWord.text = @"";
            self.secondWord.hidden = YES;
            self.secondWordBtn.hidden = YES;
            self.mainWordBtn.enabled = NO;
            self.shareToName_Constraint.constant = 5;
            self.wordViewToTimeLb_Height.constant = 10;
            [self.mainWordBtn setTitle:_model.keyword forState:UIControlStateDisabled];
            
        }else{//如果是关键字板块
            self.thirdWord_Constraint_height.constant = 22;
            self.mainWordBtn.enabled = NO;
            self.secondWordBtn.enabled = NO;
            self.thirdWord.hidden = NO;
            self.thirdWordBtn.hidden = NO;
            NSString *string = [_model.keyword stringByReplacingOccurrencesOfString:@"$" withString:@" "];
            [self.mainWordBtn setTitle:string forState:UIControlStateDisabled];
            [self.thirdWordBtn setTitle:_model.m_FileterKeyWord forState:UIControlStateDisabled];
            [self.secondWordBtn setTitle:_model.weibokeyword forState:UIControlStateDisabled];
        }
    }
}

#pragma mark - 事件点击区

- (IBAction)editeBtnClick:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(KDMSettingCell:editBtnClickWithModel:)]) {
        [_delegate KDMSettingCell:self editBtnClickWithModel:self.model];
    }
}

- (IBAction)deleteBtnClick:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(KDMSettingCell:deleteBtnClickWithModel:)]) {
        [_delegate KDMSettingCell:self deleteBtnClickWithModel:self.model];
    }
}

@end
